﻿using System;
using Autodesk.Revit.DB;
using HYRevitCode.ElementAssistUtility;

namespace Assist
{
	public class DoorWinAssistFunc
	{
		public static XYZ GetInsertPt(FamilyInstance instance)
		{
			return DoorAndWindowAssistMethod.GetInsertPt(instance);
		}

		public static double GetDoorWinWidth(FamilyInstance instance)
		{
			return DoorAndWindowAssistMethod.GetDoorWinWidth(instance);
		}

		public static XYZ GetBoundPt(FamilyInstance instance, Wall host, int index)
		{
			LocationPoint locationPoint = instance.Location as LocationPoint;
			XYZ point = locationPoint.Point;
			XYZ result = null;
			bool flag = WallAssistFunc.GetWallCurveType(host) == WallCurveType.eLineWall;
			if (flag)
			{
				XYZ startPt = WallAssistFunc.GetStartPt(host);
				XYZ xyz = new XYZ(point.X, point.Y, startPt.Z);
				XYZ xyz2 = (xyz - startPt).Normalize();
				bool flag2 = index == 0;
				if (flag2)
				{
					result = xyz + xyz2 * AssistFunc.mmToFeet(DoorWinAssistFunc.GetDoorWinWidth(instance) / 2.0);
				}
				else
				{
					bool flag3 = index == 1;
					if (flag3)
					{
						result = xyz - xyz2 * AssistFunc.mmToFeet(DoorWinAssistFunc.GetDoorWinWidth(instance) / 2.0);
					}
				}
			}
			else
			{
				bool flag4 = WallAssistFunc.GetWallCurveType(host) == WallCurveType.eArcWall;
				if (flag4)
				{
					LocationCurve locationCurve = host.Location as LocationCurve;
					Arc arc = locationCurve.Curve as Arc;
					double num = AssistFunc.mmToFeet(DoorWinAssistFunc.GetDoorWinWidth(instance) / 2.0) / arc.Radius;
					num = ((index == 0) ? num : (-num));
					Transform transform = RevitVersionFuncs.CreateRotationAtPoint(arc.Normal, num, arc.Center);
					XYZ xyz3 = new XYZ(point.X, point.Y, WallAssistFunc.GetStartPt(host).Z);
					result = transform.OfPoint(xyz3);
				}
			}
			return result;
		}
	}
}
